local zhenjun = fk.CreateSkill({
    name = "sj4__zhenjun",
  })
  
  Fk:loadTranslationTable{
    ["sj4__zhenjun"] = "镇军",
    [":sj4__zhenjun"] = "出牌阶段限一次，你可以将手牌数调整至1或4，本回合你失去所有手牌后，你令一名角色执行另一项。 ",
    
    ["#sj4__zhenjun"] = "镇军：你可以将手牌数调整至1或4，本回合你失去所有手牌后，你令一名角色执行另一项",
    ["#sj4__zhenjun-ask"] = "镇军：令一名角色将手牌数调整至%arg",
    ["@sj4__zhenjun-turn"] = "镇军",

    ["$sj4__zhenjun1"] = "奉令无犯，当敌制决！",
    ["$sj4__zhenjun2"] = "质中性一，守执节义，自当无坚不陷。",
  }

  zhenjun:addEffect("active", {
    prompt = "#sj4__zhenjun",
    target_filter = Util.FalseFunc,
    interaction = function (self, player)
      local ask = {}
      for _, n in ipairs({1,4}) do
        if player:getHandcardNum() ~= n then
          table.insert(ask,tostring(n))
        end
      end
      return UI.ComboBox{
        choices = ask,
        all_choices = {"1","4"},
      }
    end,
    can_use = function(self, player)
      return player:usedSkillTimes(zhenjun.name, Player.HistoryPhase) < 1
    end,
    card_filter = function (self, player, to_select, selected)
      local n = tonumber(self.interaction.data)
      if n > player:getHandcardNum() then
        return false
      end
      return table.contains(player:getCardIds("h"),to_select) and #selected < (player:getHandcardNum() - n) and not player:prohibitDiscard(to_select)
    end,
    feasible = function (self, player, selected, selected_cards, card)
      local n = tonumber(self.interaction.data)
      if n > player:getHandcardNum() then
        return true
      else
        return #selected_cards == (player:getHandcardNum() - n)
      end
    end,
    on_use = function(self, room, effect)
      local player = effect.from
      local n = tonumber(self.interaction.data)
      room:setPlayerMark(player,"@sj4__zhenjun-turn",n == 1 and 4 or 1)
      if #effect.cards > 0 then
        room:throwCard(effect.cards, zhenjun.name,player,player)
      else
        player:drawCards(n - player:getHandcardNum(),zhenjun.name)
      end
    end,
  })

  zhenjun:addEffect(fk.AfterCardsMove, {
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
      if not (player:hasSkill(zhenjun.name) and player:isKongcheng() and player:getMark("@sj4__zhenjun-turn") ~= 0) then return end
      for _, move in ipairs(data) do
        if move.from == player then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              return true
            end
          end
        end
      end
    end,
    on_cost = function (self, event, target, player, data)
      local room = player.room
      local p = room:askToChoosePlayers(player,{
        targets = room:getAlivePlayers(),
        min_num = 1,
        max_num = 1,
        skill_name = zhenjun.name,
        cancelable = false,
        prompt = "#sj4__zhenjun-ask:::"..player:getMark("@sj4__zhenjun-turn"),
      })[1]
      event:setCostData(self,{p = p})
      return true
    end,
    on_use = function(self, event, target, player, data)
      local p = event:getCostData(self).p
      local n = p:getHandcardNum() - player:getMark("@sj4__zhenjun-turn")
      if n < 0 then
        p:drawCards(-n,zhenjun.name)
      elseif n > 0 then
        player.room:askToDiscard(p,{
          min_num = n,
          max_num = n,
          cancelable = false,
          skill_name = zhenjun.name,
          include_equip = false,
        })
      end
    end,
  })

  return zhenjun